package com.csu.tour.controller;


import com.csu.tour.common.CommonResponse;

import com.csu.tour.entity.PerformanceGroup;

import com.csu.tour.service.PerformanceGroupService;
import com.csu.tour.vo.PerformGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/performanceGroup")
public class PerformanceGroupController {
    @Autowired
    private PerformanceGroupService performanceGroupService;

    @GetMapping
    public CommonResponse<List<PerformanceGroup>> getAll() {
        List<PerformanceGroup> performanceGroupList = performanceGroupService.findAll();
        boolean temp = performanceGroupList.isEmpty();
        //数据库查询成功但数据库中没有任何数据
        if (temp) {
            String msg = "当前没有演出团体";
            return CommonResponse.createForSuccessMessage(msg);
        } else  {
            // 创建成功响应，包含数据
            String msg = "数据库查询成功";
            return CommonResponse.createForSuccess(performanceGroupList);
        }
    }

    @GetMapping("/desc")
    public CommonResponse<List<PerformanceGroup>> getPerformanceGroupByDesc(@RequestBody PerformGroupVO performGroupVO) {
        String description = performGroupVO.getDescription();

        List<PerformanceGroup> performanceGroupList = performanceGroupService.findByDescription(description);
        boolean temp = performanceGroupList.isEmpty();
        //数据库查询成功但数据库中没有任何数据
        if (temp) {
            String msg = "当前没有演出团体";
            return CommonResponse.createForSuccessMessage(msg);
        } else  {
            // 创建成功响应，包含数据
            String msg = "数据库查询成功";
            return CommonResponse.createForSuccess(performanceGroupList);
        }
    }
}
